import { combineReducers } from 'redux'

const initialState = {
    account: '123456',
    password: '123456',
    loginInfo: {
        status: false,
        time: null,
        error: ''
    },
    NProgress: 'done',
    authRouter: [
        {
            path: "/list",
            name: '一级导航',
            children: [
                {
                    path: 'a',
                    name: '二级导航',
                    children: [
                        {
                            checked: 0,
                            path: '1',
                            name: '三级页面-1'
                        },
                        {
                            checked: 0,
                            path: '2',
                            name: '三级页面-2'
                        }
                    ]
                },
                {
                    checked: 0,
                    path: 'b',
                    name: '二级页面'
                },
                {
                    checked: 0,
                    path: 'c',
                    name: '路由传参'
                },
                {
                    checked: 0,
                    path: 'params/:user/:id',
                    name: '路由参数'
                }
            ]
        },
        {
            path: "/dialog",
            redirect: '/dialog/index',
            name: 'Dialog',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Dialog'
                }
            ]
        },
        {
            path: "/button",
            redirect: '/button/index',
            name: 'Button',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Button'
                }
            ]
        },
        {
            path: "/tag",
            redirect: '/tag/index',
            name: 'Tag',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Tag'
                }
            ]
        },
        {
            path: "/table",
            redirect: '/table/index',
            name: 'Table',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Table'
                }
            ]
        },
        {
            path: "/pagination",
            redirect: '/pagination/index',
            name: 'Pagination',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Pagination'
                }
            ]
        },
        {
            path: "/alert",
            redirect: '/alert/index',
            name: 'Alert',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Alert'
                }
            ]
        },
        {
            path: "/form",
            redirect: '/form/index',
            name: 'Form',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Form'
                }
            ]
        },
        {
            path: "/toask",
            redirect: '/toask/index',
            name: 'Toask',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Toask'
                }
            ]
        },
        {
            path: "/loading",
            redirect: '/loading/index',
            name: 'Loading',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Loading'
                }
            ]
        },
        {
            path: "/crop",
            redirect: '/crop/index',
            name: 'Crop',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Crop'
                }
            ]
        },
        {
            path: "/tooltip",
            redirect: '/tooltip/index',
            name: 'Tooltip',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Tooltip'
                }
            ]
        },
        {
            path: "/carousel",
            redirect: '/carousel/index',
            name: 'Carousel',
            children: [
                {
                    checked: 0,
                    path: 'index',
                    name: 'Carousel'
                }
            ]
        }
    ]
}

let reducers = combineReducers({
    account: (state = initialState.account, action) => {
        if(action.type === 'updateAccount'){
            return action.value
        }
        if(action.type === 'logout'){
            return '123456'
        }
        return state
    },
    password: (state = initialState.password, action) => {
        if(action.type === 'updatePassword'){
            return action.value
        }
        if(action.type === 'logout'){
            return '123456'
        }
        return state
    },
    loginInfo: (state = initialState.loginInfo, action) => {
        if(action.type === 'updateLoginStatus'){
            return action.value
        }
        if(action.type === 'logout'){
            return {
                status: false,
                time: null,
                error: '',
                role: null
            }
        }
        return state
    },
    NProgress: (state = initialState.NProgress, action) => {
        if(action.type === 'NProgress'){
            return action.value
        }
        return state
    },
    authRouter: (state = initialState.authRouter, action) => {
        if(action.type === 'setAuthRouter'){
            return [...action.value]
        }
        return state
    }
})

export default reducers